package com.carl.action;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.springframework.stereotype.Controller;

import com.carl.bean.Menu;
import com.carl.service.MenuService;
import com.carl.sysutil.StringUtil;

@Controller
public class SysMain extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4316642310844275190L;
	private List<Menu> treeResult;
	private MenuService menuSer;
	
	/**
	 * 系统中的左边的导航菜单
	 * @return
	 */
	public String leftMenu(){
		
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpSession sysSession = request.getSession();
		
		String roleId = (String) sysSession.getAttribute("role");
		treeResult = new ArrayList<>();
		
		String id = request.getParameter("id");
		
		if(StringUtil.THE_ROLE_OF_USER_IS_SYS.equals(roleId)){
			
			if(id == null || id.equals("root")){   
				treeResult = menuSer.findMenuByNodeId(null);
            }else{
            	treeResult = menuSer.findMenuByNodeId(Integer.valueOf(id));
            }
		}
		return SUCCESS;
	}

	public List<Menu> getTreeResult() {
		return treeResult;
	}

	@Resource
	public void setMenuSer(MenuService menuSer) {
		this.menuSer = menuSer;
	}
}
